//
//  ZCTabBarController.swift
//  weibo
//
//  Created by 张城 on 16/7/19.
//  Copyright © 2016年 张城. All rights reserved.
//

import UIKit

class ZCTabBarController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = ZCTabBar()
        
        tabBar.callback = {[weak self] in
            
            let pv = ZCPublishView()
            pv.publishViewShow(self!)
            
//            self.presentViewController(UINavigationController.init(rootViewController: ZCPublishController()), animated: true, completion: nil)
            
            
            
            
        }
        
        // 通过 kvc 自定义TabBar
        setValue(tabBar, forKey: "tabBar")
        
        // MARK:-- 添加模块控制器
        addChildController(ZCHomeController(), title: "首页", imgName: "tabbar_home")
        addChildController(ZCMessageController(), title: "消息", imgName: "tabbar_message_center")
        addChildController(ZCDiscoverController(), title: "发现", imgName: "tabbar_discover")
        addChildController(ZCProfileController(), title: "我", imgName: "tabbar_profile")
        
    }
    
    func addChildController(vc: ZCBaseController, title: String , imgName: String) {
        
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imgName)?.imageWithRenderingMode(.AlwaysOriginal)
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Selected)
        addChildViewController(UINavigationController(rootViewController: vc))
        
    }
    
}
